package com.shuwen.gcdj.common.util.webSocket;

import cn.hutool.json.JSONUtil;
import com.shuwen.gcdj.common.api.NoticeWebsocketResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author hf
 */
@Component
@Slf4j
public class SimpMessagingTemplateUtils {
    @Resource
    private  SimpMessagingTemplate simpMessagingTemplate;

    /**
     * 消息推送客户端，
     * @param subjectName 客户端地址
     * @param noticeWebsocketResult 返回数据
     */
    public  void sendMessageToSubject(String subjectName , NoticeWebsocketResult noticeWebsocketResult){
//        log.info("subjectName:{},data:{}", subjectName, JSONUtil.toJsonStr(noticeWebsocketResult));
        simpMessagingTemplate.convertAndSend(subjectName, JSONUtil.toJsonStr(noticeWebsocketResult));
    }

}
